package com.resou.reader.reader.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.resou.reader.R;

/**
 * 无网络页面
 */
public class NoNetworkView extends LinearLayout {
    TextView tvNet_error_text;
    ImageView iv_error;
    TextView tvInfo;
    RelativeLayout net_error_container;

    public NoNetworkView(Context context) {
        super(context);
        initView();
    }

    public NoNetworkView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.net_error_layout_read, this);
        net_error_container = view.findViewById(R.id.net_error_container);
        tvNet_error_text = view.findViewById(R.id.tvNet_error_text);
        iv_error = view.findViewById(R.id.iv_error);
        tvInfo = view.findViewById(R.id.tvInfo);
    }

    /**
     * 获取重新拉去的视图
     */
    public TextView getRetry() {
        return tvNet_error_text;
    }

    /**
     * 设置icon
     *
     * @param icon
     */
    public void setIcon(int icon) {
        iv_error.setBackgroundResource(icon);
    }

    /**
     * 字体颜色
     *
     * @param icon
     */
    public void setTextColor(int icon) {
        tvInfo.setTextColor(getResources().getColor(icon));
    }

    /**
     * 容器高度
     */
    public int getNoNetworkHeight() {
        return net_error_container.getMeasuredHeight();
    }

    /**
     * 容器宽度度
     */
    public int getNoNetworkWidth() {
        return net_error_container.getMeasuredHeight();
    }
}
